package com.insta.formation;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;

public class Main {

	private static final String FILE = "src/main/java/com/insta/library/xml/Person.xml";
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ObjectFactory obj = new ObjectFactory();
		PersonType person = obj.createPersonType();
		person.setForname(new QName("Test"));
		person.setName(new QName("Toto"));
		List<String> mailingList = person.getEmail();
		mailingList.add("toto.test@test.com");
		mailingList.add("quelqun@personne.fr");
		person.setEmail(mailingList);
		try {
			XmlUtils.marshallXML(person, new File("src/main/java/com/insta/library/xml/Person1.xml"));
		} catch (JAXBException e1) {
			e1.printStackTrace();
		}
		
		// désérialisation du fichier XML
		try {
			PersonType newPerson = XmlUtils.unmarshallXML(new FileInputStream(FILE), PersonType.class);
			System.out.println(person.getName());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

}
